package neusoft.yuejian_11.model;

import java.util.List;

import neusoft.yuejian_11.bean.MCourseBean;
import neusoft.yuejian_11.bean.MasterBean;
import neusoft.yuejian_11.bean.MasterVideoBean;
import neusoft.yuejian_11.interF.Const;
import neusoft.yuejian_11.interF.RetrofitService;
import neusoft.yuejian_11.listener.RetrofitListener;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by neusoft on 2017/10/9.
 */

public class MasterModel {
    private Retrofit retrofit;
    public MasterModel(){
        retrofit = new Retrofit.Builder()
                .baseUrl(Const.BASE_URL)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
    }
    //大师列表
    public void masterList(final RetrofitListener listener){
        RetrofitService retrofitService = retrofit.create(RetrofitService.class);
        Call<List<MasterBean>> call = retrofitService.getAllMasters();
        Callback<List<MasterBean>> callback = new Callback<List<MasterBean>>() {
            @Override
            public void onResponse(Call<List<MasterBean>> call, Response<List<MasterBean>> response) {
                List<MasterBean> masterBeen = response.body();
                listener.onSuccess(masterBeen,1);
            }

            @Override
            public void onFailure(Call<List<MasterBean>> call, Throwable t) {
                listener.onFail();
            }
        };
        call.enqueue(callback);
    }
    //大师详情
    public void getMasterById(String masterId,final RetrofitListener listener) {
        RetrofitService retrofitService=retrofit.create(RetrofitService.class);
        Call call = retrofitService.getMasterById(String.valueOf(masterId));
        call.enqueue(new Callback<MasterBean>() {
            @Override
            public void onResponse(Call<MasterBean> call, Response<MasterBean> response) {
                MasterBean masterBean=response.body();
                listener.onSuccess(masterBean,1);
            }
            @Override
            public void onFailure(Call<MasterBean> call, Throwable t) {
                listener.onFail();
            }
        });
    }
    //播放大师视频
    public void  getMasterVideos(String pm_id,final RetrofitListener listener){
        RetrofitService retrofitService = retrofit.create(RetrofitService.class);
        Call<List<MasterVideoBean>> call = retrofitService.getMasterVideos(pm_id);
        Callback<List<MasterVideoBean>> callback = new Callback<List<MasterVideoBean>>() {
            @Override
            public void onResponse(Call<List<MasterVideoBean>> call, Response<List<MasterVideoBean>> response) {
                List<MasterVideoBean> masterVideoBean = response.body();
                listener.onSuccess(masterVideoBean,1);
            }
            @Override
            public void onFailure(Call<List<MasterVideoBean>> call, Throwable t) {
                listener.onFail();
            }
        };
        call.enqueue(callback);
    }

    //大师课程列表
    public void mcourseList(String masterId, final RetrofitListener listener){
        RetrofitService retrofitService = retrofit.create(RetrofitService.class);
        Call<List<MCourseBean>> call = retrofitService.getMcourseByMaster(masterId);
        Callback<List<MCourseBean>> callback = new Callback<List<MCourseBean>>() {
            @Override
            public void onResponse(Call<List<MCourseBean>> call, Response<List<MCourseBean>> response) {
                List<MCourseBean> mCourseBeanList = response.body();
                listener.onSuccess(mCourseBeanList,1);
            }

            @Override
            public void onFailure(Call<List<MCourseBean>> call, Throwable t) {
                listener.onFail();
            }
        };
        call.enqueue(callback);
    }



}
